﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwPreostaloZaZatvaranjeZapisanoSimpleProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwPreostaloZaZatvaranjeZapisanoSimpleProviderBaseCore : EntityViewProviderBase<VwPreostaloZaZatvaranjeZapisanoSimple>
	{
		#region Custom Methods
		
		
		#region _vwPreostaloZaZatvaranjeZapisanoSimple_GetByIDKnjiz
		
		/// <summary>
		///	This method wrap the '_vwPreostaloZaZatvaranjeZapisanoSimple_GetByIDKnjiz' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt;"/> instance.</returns>
		public VList<VwPreostaloZaZatvaranjeZapisanoSimple> GetByIDKnjiz(System.Int32? @ID)
		{
			return GetByIDKnjiz(null, 0, int.MaxValue , @ID);
		}
		
		/// <summary>
		///	This method wrap the '_vwPreostaloZaZatvaranjeZapisanoSimple_GetByIDKnjiz' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt;"/> instance.</returns>
		public VList<VwPreostaloZaZatvaranjeZapisanoSimple> GetByIDKnjiz(int start, int pageLength, System.Int32? @ID)
		{
			return GetByIDKnjiz(null, start, pageLength , @ID);
		}
				
		/// <summary>
		///	This method wrap the '_vwPreostaloZaZatvaranjeZapisanoSimple_GetByIDKnjiz' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt;"/> instance.</returns>
		public VList<VwPreostaloZaZatvaranjeZapisanoSimple> GetByIDKnjiz(TransactionManager transactionManager, System.Int32? @ID)
		{
			return GetByIDKnjiz(transactionManager, 0, int.MaxValue , @ID);
		}
		
		/// <summary>
		///	This method wrap the '_vwPreostaloZaZatvaranjeZapisanoSimple_GetByIDKnjiz' stored procedure. 
		/// </summary>
		/// <param name="ID"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt;"/> instance.</returns>
		public abstract VList<VwPreostaloZaZatvaranjeZapisanoSimple> GetByIDKnjiz(TransactionManager transactionManager, int start, int pageLength , System.Int32? @ID);
		
		#endregion
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt;"/></returns>
		protected static VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt; Fill(DataSet dataSet, VList<VwPreostaloZaZatvaranjeZapisanoSimple> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwPreostaloZaZatvaranjeZapisanoSimple>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwPreostaloZaZatvaranjeZapisanoSimple>"/></returns>
		protected static VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt; Fill(DataTable dataTable, VList<VwPreostaloZaZatvaranjeZapisanoSimple> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwPreostaloZaZatvaranjeZapisanoSimple c = new VwPreostaloZaZatvaranjeZapisanoSimple();
					c.IDKnjizStavkaSimpl = (Convert.IsDBNull(row["IDKnjizStavkaSimpl"]))?(int)0:(System.Int32)row["IDKnjizStavkaSimpl"];
					c.Preostalo = (Convert.IsDBNull(row["Preostalo"]))?0:(System.Decimal?)row["Preostalo"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwPreostaloZaZatvaranjeZapisanoSimple&gt;"/></returns>
		protected VList<VwPreostaloZaZatvaranjeZapisanoSimple> Fill(IDataReader reader, VList<VwPreostaloZaZatvaranjeZapisanoSimple> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwPreostaloZaZatvaranjeZapisanoSimple entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwPreostaloZaZatvaranjeZapisanoSimple>("VwPreostaloZaZatvaranjeZapisanoSimple",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwPreostaloZaZatvaranjeZapisanoSimple();
					}
					entity.IDKnjizStavkaSimpl = (System.Int32)reader["IDKnjizStavkaSimpl"];
					//entity.IDKnjizStavkaSimpl = (Convert.IsDBNull(reader["IDKnjizStavkaSimpl"]))?(int)0:(System.Int32)reader["IDKnjizStavkaSimpl"];
					entity.Preostalo = reader.IsDBNull(reader.GetOrdinal("Preostalo")) ? null : (System.Decimal?)reader["Preostalo"];
					//entity.Preostalo = (Convert.IsDBNull(reader["Preostalo"]))?0:(System.Decimal?)reader["Preostalo"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwPreostaloZaZatvaranjeZapisanoSimple"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwPreostaloZaZatvaranjeZapisanoSimple"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwPreostaloZaZatvaranjeZapisanoSimple entity)
		{
			reader.Read();
			entity.IDKnjizStavkaSimpl = (System.Int32)reader["IDKnjizStavkaSimpl"];
			//entity.IDKnjizStavkaSimpl = (Convert.IsDBNull(reader["IDKnjizStavkaSimpl"]))?(int)0:(System.Int32)reader["IDKnjizStavkaSimpl"];
			entity.Preostalo = reader.IsDBNull(reader.GetOrdinal("Preostalo")) ? null : (System.Decimal?)reader["Preostalo"];
			//entity.Preostalo = (Convert.IsDBNull(reader["Preostalo"]))?0:(System.Decimal?)reader["Preostalo"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwPreostaloZaZatvaranjeZapisanoSimple"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwPreostaloZaZatvaranjeZapisanoSimple"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwPreostaloZaZatvaranjeZapisanoSimple entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.IDKnjizStavkaSimpl = (Convert.IsDBNull(dataRow["IDKnjizStavkaSimpl"]))?(int)0:(System.Int32)dataRow["IDKnjizStavkaSimpl"];
			entity.Preostalo = (Convert.IsDBNull(dataRow["Preostalo"]))?0:(System.Decimal?)dataRow["Preostalo"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwPreostaloZaZatvaranjeZapisanoSimple"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder : SqlFilterBuilder<VwPreostaloZaZatvaranjeZapisanoSimpleColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder class.
		/// </summary>
		public VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwPreostaloZaZatvaranjeZapisanoSimpleFilterBuilder

	#region VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwPreostaloZaZatvaranjeZapisanoSimple"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder : ParameterizedSqlFilterBuilder<VwPreostaloZaZatvaranjeZapisanoSimpleColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder class.
		/// </summary>
		public VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwPreostaloZaZatvaranjeZapisanoSimpleParameterBuilder
} // end namespace
